package com.int_tech.control.dao;

import com.int_tech.control.entity.SocketLogSend;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.Date;
import java.util.List;

/**
 * Created by liubch on 2018/1/28.
 */
public interface SocketLogSendDao extends JpaRepository<SocketLogSend,Integer>,JpaSpecificationExecutor<SocketLogSend> {
    SocketLogSend findFirstByStatusOrderByCreateTimeAsc(int status);

    SocketLogSend findFirstByStatusAndCarNumberOrderByCreateTimeAsc(int status, String s);


    @Query("select s from SocketLogSend s where s.carNumber=?1 and s.code=?2 and s.createTime<?3 order by s.createTime desc ")
    List<SocketLogSend> findByCarNumberAndCodeAndCreateTime(@Param("carNumber")String carNumber, @Param("code")String code, @Param("createTime")Date createTime);

    @Query("select s from SocketLogSend s where s.carNumber=?1 and s.code=?2 and s.createTime>?3 order by s.createTime asc ")
    List<SocketLogSend> findByCarNumberAndCodeAndCreateTimeAfter(String carNumber, String code, Date createTime);

    List<SocketLogSend> findByCode(String a0);

    @Query("select s from SocketLogSend s where s.carNumber=?1 and s.createTime>=?2 and s.createTime<=?3 order by s.createTime desc ")
    List<SocketLogSend> findByCarNumberAndCreateTimeAfterAndCreateTimeBeforeOrderByCreateTimeDesc(String carNumber, Date startOpenDoorTime, Date endCloseDoorTime);

    @Query("select s from SocketLogSend s where s.dataString like CONCAT('%',?1,'%') ")
    SocketLogSend findByDataStringLike(String rateDataString);

    @Query("select s from SocketLogSend s where s.carNumber=?1 and s.createTime>=?2 and s.createTime<=?3 order by s.createTime desc ")
    List<SocketLogSend> findByCarNumberAndStartOpenDoorTimeAndEndCloseDoorTime(String carNumber, Date startTime, Date endTime);

    List<SocketLogSend> findByType(int i);

    List<SocketLogSend> findByServiceType(String m);

    List<SocketLogSend> findByServiceTypeAndCode(String s, String a2);

    List<SocketLogSend> findByCarNumberAndCodeAndCheckStatus(String carNumber, String a0, int i);

    List<SocketLogSend> findByServiceTypeAndCreateTimeAfter(String m, Date date);

    List<SocketLogSend> findByCheckStatusAndCreateTimeBeforeOrderByCreateTimeAsc(int i, Date aaa);

    List<SocketLogSend> findByCheckStatusBeforeOrderByCreateTimeAsc(int i);

    Page<SocketLogSend> findByCodeAndCheckStatus(Pageable pageRequest, String a0, int i);

    Page<SocketLogSend> findByCodeAndCheckStatusAndCarNumber(Pageable pageRequest, String a0, int i, String s);

    @Query("select s from SocketLogSend s where s.id in (select max(id) from SocketLogSend ss where ss.code=?1 group by ss.carNumber) order by s.createTime")
    List<SocketLogSend> findGroupByIdAndCodeGroupByCarNumber(String a4);

    Page<SocketLogSend> findByCodeAndCheckStatusOrderByCreateTimeDesc(Pageable pageRequest, String a2, int i);

    Page<SocketLogSend> findByCodeAndCheckStatusAndCarNumberOrderByCreateTimeDesc(Pageable pageRequest, String a0, int i, String s);

    Page<SocketLogSend> findByCodeAndCheckStatusOrderByCreateTimeAsc(Pageable pageRequest, String a2, int i);

    Page<SocketLogSend> findByCodeAndCheckStatusAndCreateTimeAfterOrderByCreateTimeAsc(Pageable pageRequest, String a2, int i, Date date);

    Page<SocketLogSend> findByCodeAndCheckStatusAndCreateTimeAfter(Pageable pageRequest, String a0, int i, Date date);
}
